package com.tongfusoft.document.dictionary.service.impl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.tongfusoft.da.pagehelper.PageInfo;
import com.tongfusoft.da.template.service.impl.DataTemplateServiceImpl;
import com.tongfusoft.document.entity.Dictionary;
import com.tongfusoft.document.entity.DictionaryClass;
import com.tongfusoft.document.entity.Users;
import com.tongfusoft.document.manager.dictionary.service.IDocumentDictionaryService;
import com.tongfusoft.exception.ServiceException;
import com.tongfusoft.spring.web.core.data.DictionaryData;
import com.tongfusoft.spring.web.core.data.User;
import com.tongfusoft.spring.web.core.dictionary.service.IDictionaryService;
import com.tongfusoft.utils.UIDGeneratorService;

@Service("documentDictionaryService")
public class DocumentDictionaryServiceImpl extends DataTemplateServiceImpl
		implements IDictionaryService, IDocumentDictionaryService {

	@Override
	public Map<String, String> getDictByCode(Map<String, List<DictionaryData>> dictionaryMap, String dictCode) {
		return null;
	}

	@Override
	public Map<String, Map<String, String>> getDictByCode(Map<String, List<DictionaryData>> dictionaryMap,
			List<String> dictCodes) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, List<DictionaryData>> loadDict() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void createDictionary(Dictionary data, Users user) {

		if (super.selectList("dictionaryList", data).size() > 0) {

			throw new ServiceException("repeat_error");
		}
		data.setCreatedBy(user.getUserId());
		data.setLastUpdBy(user.getUserId());
		data.setLastUpdDate(new Timestamp(new Date().getTime()));
		data.setCreatedDate(new Timestamp(new Date().getTime()));
		data.setDictId(UIDGeneratorService.getUUID());
		super.insert("addDictionary", data);
	}

	@Override
	public void updateDictionary(Dictionary data, Users user) {
		// TODO Auto-generated method stub

		data.setLastUpdBy(user.getUserId());
		data.setLastUpdDate(new Timestamp(new Date().getTime()));
		super.update("updateDict", data);
	}

	@Override
	public void deleteDictionary(Dictionary data, Users user) {
		// TODO Auto-generated method stub
		data.setLastUpdBy(user.getUserId());
		data.setLastUpdDate(new Timestamp(new Date().getTime()));
		super.update("delDict", data);
	}

	@Override
	public void createDictionaryClass(DictionaryClass data, Users user) {
		if (super.selectList("dictionaryClassList", data).size() > 0) {

			throw new ServiceException("repeat_error");
		}
		data.setCreatedBy(user.getUserId());
		data.setLastUpdBy(user.getUserId());
		data.setLastUpdDate(new Timestamp(new Date().getTime()));
		data.setCreatedDate(new Timestamp(new Date().getTime()));
		data.setDictclassId(UIDGeneratorService.getUUID());
		super.insert("addDictionaryClass", data);
	}

	@Override
	public void updateDictionaryClass(DictionaryClass data, Users user) {
		// TODO Auto-generated method stub

		data.setLastUpdBy(user.getUserId());
		data.setLastUpdDate(new Timestamp(new Date().getTime()));
		this.update("updateDictClass", data);

	}

	@Override
	public void deleteDictionaryClass(DictionaryClass data, Users user) {
		// TODO Auto-generated method stub
		data.setLastUpdBy(user.getUserId());
		data.setLastUpdDate(new Timestamp(new Date().getTime()));
		this.update("delDictClass", data);
	}

	@Override
	public PageInfo<Dictionary> dictionaryPageTable(int pageIndex, int pageSize, Dictionary dict) {

		return super.findPage("dictionaryList", dict, pageSize, pageIndex);
	}

	@Override
	public PageInfo<DictionaryClass> dictCalssPageTable(int pageIndex, int pageSize, DictionaryClass dictClass) {

		return super.findPage("dictionaryClassList", dictClass, pageSize, pageIndex);
	}

	@Override
	public DictionaryClass getDictClass(DictionaryClass dictClass) {
		// TODO Auto-generated method stub

		return (DictionaryClass) this.selectOne("dictionaryClassList", dictClass);
	}

	@Override
	public Dictionary getDict(Dictionary dict) {
		// TODO Auto-generated method stub
		return (Dictionary) this.selectOne("dictionaryList", dict);
	}

	@Override
	public List<Dictionary> getDictionaryListByDictClassId(DictionaryClass dictionary) {
		
		return this.selectList("getDictionaryListByDictClass", dictionary);
	}

	@Override
	public List<Dictionary> getDictByCode(String dictclassCode) {
		// TODO Auto-generated method stub
		DictionaryClass dc  = new DictionaryClass();
		dc.setDictclassCode(dictclassCode);
		return getDictionaryListByDictClassId(dc);
	}


}
